{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# 商品期权T型报价\n",
    "商品期权T型报价的接口为\n",
    "\n",
    "`optshare.get_commodity_option_quotes(exchange_name, calendar=optshare.Calendar(), display=True)`\n",
    "\n",
    "其中，\n",
    "\n",
    "- **exchange_name**: 指定交易所名称，支持大商所(`'dce'`)、郑商所(`'czce'`)、上期所(`'shfe'`)、上海国际能源(`'ine'`)的商品期权T型报价。\n",
    "- **calendar**: 指定交易日历，默认值为`optshare.Calendar()`，默认使用[在线节假日信息](https://gitee.com/luluUCD/optshare/raw/master/src/optshare/dateutils/China.txt)，也可以通过指定带有节假日列表的txt文件来指定交易日历，更多信息详见[日历接口](https://optshare.readthedocs.io/en/latest/api_references/optshare.dateutils.html#calendar-definition)。\n",
    "- **display**: 在获取T型报价时，是否展示期权报价的种类，默认值为True。"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 大连商品交易所"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fetch option quotes for  豆粕期权\n",
      "fetch option quotes for  玉米期权\n",
      "fetch option quotes for  铁矿石期权\n",
      "fetch option quotes for  液化石油天然气期权\n",
      "fetch option quotes for  聚乙烯期权\n",
      "fetch option quotes for  聚氯乙烯期权\n",
      "fetch option quotes for  聚丙烯期权\n",
      "fetch option quotes for  棕榈油期权\n",
      "fetch option quotes for  黄大豆1号期权\n",
      "fetch option quotes for  黄大豆2号期权\n",
      "fetch option quotes for  豆油期权\n"
     ]
    },
    {
     "data": {
      "text/plain": "                    日期     行权价  看涨合约-最新价  看跌合约-最新价 挂钩标的代码        到期日期\n0     2023-02-16 11:21  2850.0       NaN       1.0  m2305  2023-04-10\n1     2023-02-16 11:21  2900.0       NaN       NaN  m2305  2023-04-10\n2     2023-02-16 11:21  2950.0       NaN       NaN  m2305  2023-04-10\n3     2023-02-16 11:21  3000.0       NaN       1.0  m2305  2023-04-10\n4     2023-02-16 11:21  3050.0       NaN       1.5  m2305  2023-04-10\n...                ...     ...       ...       ...    ...         ...\n3353  2023-02-16 11:21  9400.0       NaN       NaN  y2401  2023-12-07\n3354  2023-02-16 11:21  9500.0       NaN       NaN  y2401  2023-12-07\n3355  2023-02-16 11:21  9600.0       NaN       NaN  y2401  2023-12-07\n3356  2023-02-16 11:21  9700.0       NaN       NaN  y2401  2023-12-07\n3357  2023-02-16 11:21  9800.0       NaN       NaN  y2401  2023-12-07\n\n[3358 rows x 6 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>日期</th>\n      <th>行权价</th>\n      <th>看涨合约-最新价</th>\n      <th>看跌合约-最新价</th>\n      <th>挂钩标的代码</th>\n      <th>到期日期</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2023-02-16 11:21</td>\n      <td>2850.0</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>m2305</td>\n      <td>2023-04-10</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2023-02-16 11:21</td>\n      <td>2900.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>m2305</td>\n      <td>2023-04-10</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2023-02-16 11:21</td>\n      <td>2950.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>m2305</td>\n      <td>2023-04-10</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2023-02-16 11:21</td>\n      <td>3000.0</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>m2305</td>\n      <td>2023-04-10</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2023-02-16 11:21</td>\n      <td>3050.0</td>\n      <td>NaN</td>\n      <td>1.5</td>\n      <td>m2305</td>\n      <td>2023-04-10</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>3353</th>\n      <td>2023-02-16 11:21</td>\n      <td>9400.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>y2401</td>\n      <td>2023-12-07</td>\n    </tr>\n    <tr>\n      <th>3354</th>\n      <td>2023-02-16 11:21</td>\n      <td>9500.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>y2401</td>\n      <td>2023-12-07</td>\n    </tr>\n    <tr>\n      <th>3355</th>\n      <td>2023-02-16 11:21</td>\n      <td>9600.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>y2401</td>\n      <td>2023-12-07</td>\n    </tr>\n    <tr>\n      <th>3356</th>\n      <td>2023-02-16 11:21</td>\n      <td>9700.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>y2401</td>\n      <td>2023-12-07</td>\n    </tr>\n    <tr>\n      <th>3357</th>\n      <td>2023-02-16 11:21</td>\n      <td>9800.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>y2401</td>\n      <td>2023-12-07</td>\n    </tr>\n  </tbody>\n</table>\n<p>3358 rows × 6 columns</p>\n</div>"
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import optshare\n",
    "optshare.get_commodity_option_quotes(exchange_name= 'dce')"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 郑州商品交易所"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fetch option quotes for  白糖期权\n",
      "fetch option quotes for  棉花期权\n",
      "fetch option quotes for  PTA期权\n",
      "fetch option quotes for  甲醇期权\n",
      "fetch option quotes for  菜籽粕期权\n",
      "fetch option quotes for  菜籽油期权\n",
      "fetch option quotes for  花生期权\n"
     ]
    },
    {
     "data": {
      "text/plain": "                   日期     行权价  看涨合约-最新价  看跌合约-最新价 挂钩标的代码        到期日期\n0    2023-02-16 11:21  5000.0     881.0       0.5  SR305  2023-04-06\n1    2023-02-16 11:21  5100.0       NaN       1.0  SR305  2023-04-06\n2    2023-02-16 11:21  5200.0       NaN       1.5  SR305  2023-04-06\n3    2023-02-16 11:21  5300.0     586.0       1.5  SR305  2023-04-06\n4    2023-02-16 11:21  5400.0       NaN       2.0  SR305  2023-04-06\n..                ...     ...       ...       ...    ...         ...\n794  2023-02-16 11:21  9500.0       NaN       NaN  PK310  2023-09-05\n795  2023-02-16 11:21  9600.0       NaN       NaN  PK310  2023-09-05\n796  2023-02-16 11:21  9700.0       NaN       NaN  PK310  2023-09-05\n797  2023-02-16 11:21  9800.0       NaN     189.0  PK310  2023-09-05\n798  2023-02-16 11:21  9900.0       NaN       NaN  PK310  2023-09-05\n\n[799 rows x 6 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>日期</th>\n      <th>行权价</th>\n      <th>看涨合约-最新价</th>\n      <th>看跌合约-最新价</th>\n      <th>挂钩标的代码</th>\n      <th>到期日期</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2023-02-16 11:21</td>\n      <td>5000.0</td>\n      <td>881.0</td>\n      <td>0.5</td>\n      <td>SR305</td>\n      <td>2023-04-06</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2023-02-16 11:21</td>\n      <td>5100.0</td>\n      <td>NaN</td>\n      <td>1.0</td>\n      <td>SR305</td>\n      <td>2023-04-06</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2023-02-16 11:21</td>\n      <td>5200.0</td>\n      <td>NaN</td>\n      <td>1.5</td>\n      <td>SR305</td>\n      <td>2023-04-06</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2023-02-16 11:21</td>\n      <td>5300.0</td>\n      <td>586.0</td>\n      <td>1.5</td>\n      <td>SR305</td>\n      <td>2023-04-06</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2023-02-16 11:21</td>\n      <td>5400.0</td>\n      <td>NaN</td>\n      <td>2.0</td>\n      <td>SR305</td>\n      <td>2023-04-06</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>794</th>\n      <td>2023-02-16 11:21</td>\n      <td>9500.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>PK310</td>\n      <td>2023-09-05</td>\n    </tr>\n    <tr>\n      <th>795</th>\n      <td>2023-02-16 11:21</td>\n      <td>9600.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>PK310</td>\n      <td>2023-09-05</td>\n    </tr>\n    <tr>\n      <th>796</th>\n      <td>2023-02-16 11:21</td>\n      <td>9700.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>PK310</td>\n      <td>2023-09-05</td>\n    </tr>\n    <tr>\n      <th>797</th>\n      <td>2023-02-16 11:21</td>\n      <td>9800.0</td>\n      <td>NaN</td>\n      <td>189.0</td>\n      <td>PK310</td>\n      <td>2023-09-05</td>\n    </tr>\n    <tr>\n      <th>798</th>\n      <td>2023-02-16 11:21</td>\n      <td>9900.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>PK310</td>\n      <td>2023-09-05</td>\n    </tr>\n  </tbody>\n</table>\n<p>799 rows × 6 columns</p>\n</div>"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "optshare.get_commodity_option_quotes(exchange_name='czce')"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 上海期货交易所"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fetch option quotes for  铜期权\n",
      "fetch option quotes for  铝期权\n",
      "fetch option quotes for  锌期权\n",
      "fetch option quotes for  螺纹钢期权\n",
      "fetch option quotes for  黄金期权\n",
      "fetch option quotes for  白银期权\n",
      "fetch option quotes for  天胶期权\n"
     ]
    },
    {
     "data": {
      "text/plain": "                    日期      行权价  看涨合约-最新价  看跌合约-最新价  挂钩标的代码        到期日期\n0     2023-02-16 11:21  50000.0       NaN       2.0  cu2303  2023-02-22\n1     2023-02-16 11:21  51000.0       NaN       2.0  cu2303  2023-02-22\n2     2023-02-16 11:21  52000.0       NaN       NaN  cu2303  2023-02-22\n3     2023-02-16 11:21  53000.0       NaN       NaN  cu2303  2023-02-22\n4     2023-02-16 11:21  54000.0       NaN       2.0  cu2303  2023-02-22\n...                ...      ...       ...       ...     ...         ...\n1173  2023-02-16 11:21  14250.0       NaN    1872.0  ru2309  2023-08-25\n1174  2023-02-16 11:21  14500.0     227.0       NaN  ru2309  2023-08-25\n1175  2023-02-16 11:21  14750.0     200.0       NaN  ru2309  2023-08-25\n1176  2023-02-16 11:21  15000.0     174.0       NaN  ru2309  2023-08-25\n1177  2023-02-16 11:21  15250.0     151.0       NaN  ru2309  2023-08-25\n\n[1178 rows x 6 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>日期</th>\n      <th>行权价</th>\n      <th>看涨合约-最新价</th>\n      <th>看跌合约-最新价</th>\n      <th>挂钩标的代码</th>\n      <th>到期日期</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2023-02-16 11:21</td>\n      <td>50000.0</td>\n      <td>NaN</td>\n      <td>2.0</td>\n      <td>cu2303</td>\n      <td>2023-02-22</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2023-02-16 11:21</td>\n      <td>51000.0</td>\n      <td>NaN</td>\n      <td>2.0</td>\n      <td>cu2303</td>\n      <td>2023-02-22</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2023-02-16 11:21</td>\n      <td>52000.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>cu2303</td>\n      <td>2023-02-22</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2023-02-16 11:21</td>\n      <td>53000.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>cu2303</td>\n      <td>2023-02-22</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2023-02-16 11:21</td>\n      <td>54000.0</td>\n      <td>NaN</td>\n      <td>2.0</td>\n      <td>cu2303</td>\n      <td>2023-02-22</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>1173</th>\n      <td>2023-02-16 11:21</td>\n      <td>14250.0</td>\n      <td>NaN</td>\n      <td>1872.0</td>\n      <td>ru2309</td>\n      <td>2023-08-25</td>\n    </tr>\n    <tr>\n      <th>1174</th>\n      <td>2023-02-16 11:21</td>\n      <td>14500.0</td>\n      <td>227.0</td>\n      <td>NaN</td>\n      <td>ru2309</td>\n      <td>2023-08-25</td>\n    </tr>\n    <tr>\n      <th>1175</th>\n      <td>2023-02-16 11:21</td>\n      <td>14750.0</td>\n      <td>200.0</td>\n      <td>NaN</td>\n      <td>ru2309</td>\n      <td>2023-08-25</td>\n    </tr>\n    <tr>\n      <th>1176</th>\n      <td>2023-02-16 11:21</td>\n      <td>15000.0</td>\n      <td>174.0</td>\n      <td>NaN</td>\n      <td>ru2309</td>\n      <td>2023-08-25</td>\n    </tr>\n    <tr>\n      <th>1177</th>\n      <td>2023-02-16 11:21</td>\n      <td>15250.0</td>\n      <td>151.0</td>\n      <td>NaN</td>\n      <td>ru2309</td>\n      <td>2023-08-25</td>\n    </tr>\n  </tbody>\n</table>\n<p>1178 rows × 6 columns</p>\n</div>"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "optshare.get_commodity_option_quotes(exchange_name='shfe')"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 上海国际能源交易中心"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fetch option quotes for  原油期权\n"
     ]
    },
    {
     "data": {
      "text/plain": "                  日期    行权价  看涨合约-最新价  看跌合约-最新价  挂钩标的代码        到期日期\n0   2023-02-16 11:21  420.0       NaN      0.10  sc2304  2023-03-15\n1   2023-02-16 11:21  425.0       NaN      0.10  sc2304  2023-03-15\n2   2023-02-16 11:21  430.0       NaN      0.15  sc2304  2023-03-15\n3   2023-02-16 11:21  435.0    125.95      0.15  sc2304  2023-03-15\n4   2023-02-16 11:21  440.0       NaN      0.15  sc2304  2023-03-15\n..               ...    ...       ...       ...     ...         ...\n67  2023-02-16 11:21  650.0      5.15       NaN  sc2305  2023-04-12\n68  2023-02-16 11:21  660.0      4.00       NaN  sc2305  2023-04-12\n69  2023-02-16 11:21  670.0      3.15       NaN  sc2305  2023-04-12\n70  2023-02-16 11:21  680.0      2.40       NaN  sc2305  2023-04-12\n71  2023-02-16 11:21  690.0      1.85       NaN  sc2305  2023-04-12\n\n[72 rows x 6 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>日期</th>\n      <th>行权价</th>\n      <th>看涨合约-最新价</th>\n      <th>看跌合约-最新价</th>\n      <th>挂钩标的代码</th>\n      <th>到期日期</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2023-02-16 11:21</td>\n      <td>420.0</td>\n      <td>NaN</td>\n      <td>0.10</td>\n      <td>sc2304</td>\n      <td>2023-03-15</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2023-02-16 11:21</td>\n      <td>425.0</td>\n      <td>NaN</td>\n      <td>0.10</td>\n      <td>sc2304</td>\n      <td>2023-03-15</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2023-02-16 11:21</td>\n      <td>430.0</td>\n      <td>NaN</td>\n      <td>0.15</td>\n      <td>sc2304</td>\n      <td>2023-03-15</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2023-02-16 11:21</td>\n      <td>435.0</td>\n      <td>125.95</td>\n      <td>0.15</td>\n      <td>sc2304</td>\n      <td>2023-03-15</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2023-02-16 11:21</td>\n      <td>440.0</td>\n      <td>NaN</td>\n      <td>0.15</td>\n      <td>sc2304</td>\n      <td>2023-03-15</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>67</th>\n      <td>2023-02-16 11:21</td>\n      <td>650.0</td>\n      <td>5.15</td>\n      <td>NaN</td>\n      <td>sc2305</td>\n      <td>2023-04-12</td>\n    </tr>\n    <tr>\n      <th>68</th>\n      <td>2023-02-16 11:21</td>\n      <td>660.0</td>\n      <td>4.00</td>\n      <td>NaN</td>\n      <td>sc2305</td>\n      <td>2023-04-12</td>\n    </tr>\n    <tr>\n      <th>69</th>\n      <td>2023-02-16 11:21</td>\n      <td>670.0</td>\n      <td>3.15</td>\n      <td>NaN</td>\n      <td>sc2305</td>\n      <td>2023-04-12</td>\n    </tr>\n    <tr>\n      <th>70</th>\n      <td>2023-02-16 11:21</td>\n      <td>680.0</td>\n      <td>2.40</td>\n      <td>NaN</td>\n      <td>sc2305</td>\n      <td>2023-04-12</td>\n    </tr>\n    <tr>\n      <th>71</th>\n      <td>2023-02-16 11:21</td>\n      <td>690.0</td>\n      <td>1.85</td>\n      <td>NaN</td>\n      <td>sc2305</td>\n      <td>2023-04-12</td>\n    </tr>\n  </tbody>\n</table>\n<p>72 rows × 6 columns</p>\n</div>"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "optshare.get_commodity_option_quotes(exchange_name='ine')"
   ],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
